package com.zr.action;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.datamodel.RcdReceivingDM;
import com.zr.dto.RedReceivingDM;
import com.zr.service.ReprotService;

import net.sf.json.JSONObject;
/**
 * 获取全部数据
 * @author Administrator
 *
 */

public class ReprotAction extends ActionSupport implements ServletResponseAware{
	private  HttpServletResponse  resp;
	private RedReceivingDM redReceivingDM;
	private int page;
	private int rows;
	private String year;
	private String month;
	private int quarter;//季度
	
	public void setMonth(String month) {
		this.month = month;
	}
	
	public int getQuarter() {
		return quarter;
	}

	public void setQuarter(int quarter) {
		this.quarter = quarter;
	}

	public String getYear() {
		return year;
	}
	public void setYear(String year) {
		this.year = year;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	@Resource
	private ReprotService reprotservice;
	
	public RedReceivingDM getRedReceivingDM() {
		return redReceivingDM;
	}
	public void setRedReceivingDM(RedReceivingDM redReceivingDM) {
		this.redReceivingDM = redReceivingDM;
	}
	/**
	 * 收货报表
	 */
	public void  showReprot(){
		resp.setCharacterEncoding("utf-8");
		JSONObject obj = null;
		String[] months = new String[3];
		if (quarter == 1) {
			months[0]="01";
			months[1]="02";
			months[2]="03";
		}else if(quarter == 2){
			months[0]="04";
			months[1]="05";
			months[2]="06";
		}else if(quarter == 3){
			months[0]="07";
			months[1]="08";
			months[2]="09";
		}else if(quarter == 4){
			months[0]="10";
			months[1]="11";
			months[2]="12";
		}else{
			months[0]=month;
		}
		
		obj = reprotservice.selectRecReprotMsg(year, months, page, rows);
		try {
			resp.getWriter().write(obj.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	/**
	 * 发货报表
	 */
	public void showDelReprot(){
		resp.setCharacterEncoding("utf-8");
		JSONObject obj = null;
		String[] months = new String[3];
		if (quarter == 1) {
			months[0]="01";
			months[1]="02";
			months[2]="03";
		}else if(quarter == 2){
			months[0]="04";
			months[1]="05";
			months[2]="06";
		}else if(quarter == 3){
			months[0]="07";
			months[1]="08";
			months[2]="09";
		}else if(quarter == 4){
			months[0]="10";
			months[1]="11";
			months[2]="12";
		}else{
            months[0]=month;			
		}
		obj = reprotservice.selectDelReprotMsg(year, months, page, rows);
		try {
			resp.getWriter().write(obj.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
    
	/**
	 * 收发货总表
	 */
	public void showRDReprot(){
		resp.setCharacterEncoding("utf-8");
		JSONObject obj = null;
		String[] months = new String[3];
		if (quarter == 1) {
			months[0]="01";
			months[1]="02";
			months[2]="03";
		}else if(quarter == 2){
			months[0]="04";
			months[1]="05";
			months[2]="06";
		}else if(quarter == 3){
			months[0]="07";
			months[1]="08";
			months[2]="09";
		}else if(quarter == 4){
			months[0]="10";
			months[1]="11";
			months[2]="12";
		}else{
            months[0]=month;			
		}
		obj = reprotservice.selectDelReprotMsg(year, months, page, rows);
		try {
			resp.getWriter().write(obj.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * 省公司收入报表
	 */
	public void showGrossed(){
		resp.setCharacterEncoding("utf-8");
		JSONObject obj = null;
		String[] months = new String[3];
		if (quarter == 1) {
			months[0]="01";
			months[1]="02";
			months[2]="03";
		}else if(quarter == 2){
			months[0]="04";
			months[1]="05";
			months[2]="06";
		}else if(quarter == 3){
			months[0]="07";
			months[1]="08";
			months[2]="09";
		}else if(quarter == 4){
			months[0]="10";
			months[1]="11";
			months[2]="12";
		}else{
            months[0]=month;			
		}
		obj = reprotservice.selectGReprotMsg(year, months, page, rows);
		try {
			resp.getWriter().write(obj.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Override
	public void setServletResponse(HttpServletResponse resp) {
		// TODO Auto-generated method stub
		this.resp = resp;
	}
      
}
